package org.ThreadDemo.pool;

import java.util.concurrent.*;

public class ThreadPoolDemo2 {

    public static void main(String[] args) {

        ExecutorService threadpool = new ThreadPoolExecutor(2,
                10,
                2L,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(3),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
                );

        try{
            for(int i =0;i<=20;i++) {
                threadpool.execute(
                        ()->{
                            System.out.println(Thread.currentThread().getName()+"办理业务");
                            try {
                                TimeUnit.SECONDS.sleep(3);
                            } catch (InterruptedException e) {
                                throw new RuntimeException(e);
                            }
                        }
                );

            }
        }catch(Exception e) {
            e.printStackTrace();
        }finally{
            threadpool.shutdown();
        }


    }
}
